package com.example.sunny.service.receiver

import android.app.AlarmManager
import android.app.PendingIntent
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import java.util.*

object AlarmTimer {
    //周期性闹钟
    val TIMER_ACTION_REPEATING = "com.sunny.TIMER_ACTION_REPEATING"

    fun setRepeatingAlarmTimer(context: Context,firstTime:Long,cycleTime:Long,action:String,alarmManagerType:Int){
        val intent = Intent()
        intent.action = action
        var alarmCount = 0
        val sender = PendingIntent.getService(context, alarmCount++, intent, PendingIntent.FLAG_UPDATE_CURRENT)
        val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager

        //设置在11:49开始
        val calender = Calendar.getInstance().apply {
            set(Calendar.HOUR_OF_DAY,11)
            set(Calendar.MINUTE,49)
        }
        alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calender.timeInMillis,cycleTime,sender)
    }
}